def sort01(ll):
    s = 0
    print(ll)
    # sort
    for j in range(0, len(ll)):
        for i in range(1, len(ll) - j):
            s += 1
            if ll[i - 1] > ll[i]:
                ll[i - 1], ll[i] = ll[i], ll[i - 1]
    return s


def sort02(ll):
    flag = len(ll)
    s = 0
    # print(ll)
    # sort
    for j in range(0, len(ll)):
        sort = True
        for i in range(1, flag):
            s += 1
            if ll[i - 1] > ll[i]:
                ll[i - 1], ll[i] = ll[i], ll[i - 1]
                sort = False
                flag = i
                # print(ll, flag)
        if sort:
            # print('break',ll)
            break
    return s


if __name__ == '__main__':
    l = [2, 8, 3, 7, 6, 5, 9, 1, 4, 0, -1, 2, -9, 5, 9, 1]
    l02 = l
    print(sort02(l02))
    print('l:', l)
    print('l02:', l02)

    def add_two(a):
        print('b in function:', b)
        a += 2
        return a


    b = 5
    print('add_two:', add_two(b))
    print('b:', b)
